﻿using AutoMapper;
using MediatR;
using Traceability.APP.Application.Command.Deepprocessings;
using Traceability.APP.Application.Command.Pictures;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Deepprocessings
{
    public class AddMachiningEnterpriseCommandHandLer : IRequestHandler<AddMachiningEnterpriseCommand, APIResult<int>>
    {

        private readonly IBaseRepostiy<MachiningEnterprise> _machiningEnterprise;
        private readonly IMapper mapper;

        public AddMachiningEnterpriseCommandHandLer(IBaseRepostiy<MachiningEnterprise> machiningEnterprise, IMapper mapper)
        {
            _machiningEnterprise = machiningEnterprise;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(AddMachiningEnterpriseCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var list = mapper.Map<MachiningEnterprise>(request);

            var res = await _machiningEnterprise.AddAsync(list);
            result.Code = ResultCode.Ok;
            result.Message = "企业信息添加成功";
            result.Data = res;
            return await Task.FromResult(result);
        }
    }
}
